package com.yy.druid.configuration;

import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author yangyao
 * @Description: TODO
 * @date 2018/10/8 10:51
 */
@Configuration
public class DruidConfiguration {
    @Bean
   public ServletRegistrationBean statViewServlet(){

        ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new StatViewServlet(),"/druid/*");
        //设置允许ip
        servletRegistrationBean.addInitParameter("allow","127.0.0.1");
        //设置ip黑名单，allow和deny同时存在是，deny高于allow
        servletRegistrationBean.addInitParameter("deny","192.168.1.1");
        servletRegistrationBean.addInitParameter("loginUsername","admin");
        servletRegistrationBean.addInitParameter("loginPassword","123");
        servletRegistrationBean.addInitParameter("resetEnable","false");
        return servletRegistrationBean;
    }
    @Bean
    public FilterRegistrationBean statFilter(){
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new WebStatFilter());
        filterRegistrationBean.addUrlPatterns("/*");
        filterRegistrationBean.addInitParameter("exclusions","*.js,*.css,*.icon,/druid/*");
        return filterRegistrationBean;
    }
}
